package delete

import (
	"context"

	"server_1.0/api/internal/svc"
	"server_1.0/api/internal/types"
	"server_1.0/service/major/major"
	"server_1.0/util"

	"github.com/zeromicro/go-zero/core/logx"
)

type DeleteMajorLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewDeleteMajorLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteMajorLogic {
	return &DeleteMajorLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *DeleteMajorLogic) DeleteMajor(req *types.MajDeleteReq) (resp *types.PostReps, err error) {

	code := util.Success
	Msg := "删除成功"

	del, _ := l.svcCtx.MajorRpc.Delete(l.ctx, &major.DeleteReq{
		No: req.Mno,
	})
	if del.Count == 0 {
		code = util.DelError
		Msg = "删除失败"
	}

	return &types.PostReps{
		Code: code,
		Msg:  Msg,
		Data: map[string]interface{}{
			"res": del.QRs,
		},
	}, nil
}
